# 为了限制score的范围，可以通过一个set_score()方法来设置成绩，
# 再通过一个get_score()来获取成绩，这样，在set_score()方法里，就可以检查参数：


class Student(object):
    def set_score(self, value):
        if not isinstance(value, int):
            raise ValueError('score must be an integer!')
        if value < 0 or value > 100:
            raise ValueError('score must between 0 ~ 100!')
        self._score = value

    def get_score(self):
        return self._score


stu1 = Student()
stu1.set_score(99)
print(stu1.get_score())
print(dir(stu1))
print(hasattr(stu1, '_score'))


class Teacher(object):
    @property  # property 标注标示下方定义的函数是getter方法
    def salary(self):
        return self._salary

    @salary.setter  # function的名称.setter 标注的是函数的setter方法
    def salary(self, value):
        if not isinstance(value, int):
            raise ValueError('Salary must be an integer!')
        if value < 0:
            raise ValueError('Salary must bigger than zero!')
        self._salary = value

    @property
    def tax(self):
        return self._salary * 0.015


t1 = Teacher()
t1.salary = 10000
print(t1.salary)
print(t1.tax)

